package org.example.database.Mapper;


import org.apache.ibatis.annotations.*;
import org.example.database.entity.RecruitmentPosition;

import java.util.List;

@Mapper
public interface RecruitmentPositionMapper {
    /**
     * 插入职位信息
     * @param position 职位信息
     * @return 影响行数
     */
    @Insert("INSERT INTO recruitment_position (jobName, department, recruitingNumber, place, salary, " +
            "educationalRequirement, jobDescription) VALUES (#{jobName}, #{department}, #{recruitingNumber}, " +
            "#{place}, #{salary}, #{educationalRequirement}, #{jobDescription})")
    @Options(useGeneratedKeys = true, keyProperty = "jobNumber")
    int insert(RecruitmentPosition position);

    /**
     * 根据ID查询职位
     * @param jobNumber 职位ID
     * @return 职位信息
     */
    @Select("SELECT * FROM recruitment_position WHERE jobNumber = #{jobNumber}")
    RecruitmentPosition selectById(Integer jobNumber);

    /**
     * 查询所有职位
     * @return 职位列表
     */
    @Select("SELECT * FROM recruitment_position")
    List<RecruitmentPosition> selectAll();

    /**
     * 根据学历要求查询职位
     * @param educationalRequirement 学历要求
     * @return 职位列表
     */
    @Select("SELECT * FROM recruitment_position WHERE educationalRequirement = #{educationalRequirement}")
    List<RecruitmentPosition> selectByEducationalRequirement(String educationalRequirement);

    /**
     * 更新职位信息
     * @param position 职位信息
     * @return 影响行数
     */
    @Update("UPDATE recruitment_position SET jobName = #{jobName}, department = #{department}, " +
            "recruitingNumber = #{recruitingNumber}, place = #{place}, salary = #{salary}, " +
            "educationalRequirement = #{educationalRequirement}, jobDescription = #{jobDescription} " +
            "WHERE jobNumber = #{jobNumber}")
    int update(RecruitmentPosition position);

    /**
     * 删除职位
     * @param jobNumber 职位ID
     * @return 影响行数
     */
    @Delete("DELETE FROM recruitment_position WHERE jobNumber = #{jobNumber}")
    int deleteById(Integer jobNumber);
}